#include <iostream>
#include <string>

// 抽象球类
class IBall {
    public:
    IBall(){}
    // 抽象方法
    virtual void play() = 0;
};

// 具体球类
class Basketball : public IBall {
    public:
    Basketball() {
        play();
    }

    virtual void play() {
        std::cout << "play Basketball" << std::endl;
    }
};

// 抽象Shirt类
class IShirt {
    public:
    IShirt() {}
    // 抽象方法
    virtual void wearShirt() = 0;

};

// 具体Shirt类
class BasketballShirt : public IShirt {
    public:
    BasketballShirt() {
        wearShirt();
    }

    virtual void wearShirt() {
        std::cout << "wear Basketball Shirt" << std::endl;
    }
};

// 抽象工厂类
class IFactory {
    public:
    IFactory(){}
    virtual IBall* getBall() = 0;
    virtual IShirt* getShirt() = 0;

};

// 具体BasketBallFactory,重新实现两个方法getBall 和 wearShirt
class BasketBallFactory : public IFactory {
    public:
    BasketBallFactory() {
        std::cout << "BasketBallFactory" << std::endl;
    }

    virtual IBall* getBall() {
        std::cout << "get basketball\n";
        return new Basketball();
    }

    virtual IShirt* getShirt() {
        std::cout << "get basketballShirt\n";
        return new BasketballShirt();        
    }
};

int main () {
    std::cout << "hello abstract_factory!!!" << std::endl;
    IFactory* f = new BasketBallFactory();
    IBall* b = f->getBall();
    IShirt* s = f->getShirt();

    delete f;
    delete b;
    delete s;
    f = nullptr;
    b = nullptr;
    s = nullptr;
    return 0;
}